home *** CD-ROM | disk | FTP | other *** search
- @echo off
- ! trash.bat Batch file to move files and folders to the trash bin
- !
- ! This program emulates the trashing of files and folders as done by the Mac
- ! when a user drags items to the Trash
- ! Just type:
- ! trash name
- ! where 'name' can be a file name (wildcarded or not) or a folder name
- !
- ! *** WARNING ***
- ! The Trash of the startup volume is used, regardless of whether the items to be
- ! trashed are on that volume or not.
- !
- ! Copyright © 1993 by Rainbow Hill Pty Ltd. All rights reserved.
- !
-
- echo Files and folders being copied:
-
- ! set up the handling of errors
- onerror ERR_LBL
-
- ! first check whether the user has typed a parameter
- if not "%1 " == " " goto SYNTAX_DONE_LBL
- echo No arguments. Type trash/? for help
- goto DONE_LBL
- :SYNTAX_DONE_LBL
-
- ! check whether help is requested
- ! the space before /? is needed because the presence of a parameter equal to
- ! /? overrides everything else. We would then get the IF's help !
- if not " %1" == " /?" goto HELP_DONE_LBL
- echo Trashes a file or a folder
- echo.
- echo TRASH name
- echo name: file[s] or folder to be trashed.
- echo Note that the name cannot contain a path.
- echo.
- goto DONE_LBL
- :HELP_DONE_LBL
-
- ! check that the user has not typed more than one parameter
- if "%2 " == " " goto SYNTAX1_DONE_LBL
- echo Too many parameters. Type trash/? for help
- goto DONE_LBL
- :SYNTAX1_DONE_LBL
-
- ! check whether the user wants to copy a single file or a wildcarded
- ! filename (EXIST ignores the folders). If so, fall through and do a
- ! straight COPY.
- if not exist %1 goto FOLDER_LBL
- copy %1 1:\trash
- del %1
- goto DONE_LBL
-
- :FOLDER_LBL
- ! Either the item is a folder or does not exist at all.
- ! Check whether it is a folder.
- if existdir %1 goto FOLDER_OK_LBL
- set doserr=27
- goto ERR_LBL
- :FOLDER_OK_LBL
-
- ! extract the folder name from the path
- set foldername=%1
- ! extract what follows the last backslash (if there is one)
- onerror NO_SLASH_LBL
- sstr foldername "\" /e /r
- goto FOLDERNAME_DONE_LBL
- :NO_SLASH_LBL
- ! if the error just says that there is no backslash, just fall through
- if not %doserr% == 72 goto ERR_LBL
- ! try to extract what follows the first colon (remember, there is no backslash)
- onerror NO_COLON_LBL
- sstr foldername ":" /r
- goto FOLDERNAME_DONE_LBL
- :NO_COLON_LBL
- ! if the error just says that there is no colon, just fall through
- if not %doserr% == 72 goto ERR_LBL
-
- :FOLDERNAME_DONE_LBL
- ! restore the standard error handling before doing anything else
- onerror ERR_LBL
-
- ! check that the user does not want to delete a parent folder
- if not %foldername% == .. goto FOLDERNAME_OK_LBL
- echo Illegal path (it ends with a ".."). Type trash/? for help
- goto DONE_LBL
- :FOLDERNAME_OK_LBL
-
- ! create in the Trash a folder with the requested name
- ! this is necessary because XCOPY does not copy the folder itself
- onerror CREATE_ERR_LBL
- :CREATE_LBL
- md 1:\trash\%foldername%
- goto CREATE_DONE_LBL
- :CREATE_ERR_LBL
- if not %doserr% == 58 goto ERR_LBL
- incr foldername by $
- goto CREATE_LBL
- :CREATE_DONE_LBL
- onerror ERR_LBL
-
- ! XCOPY everything to the newly created folder
- xcopy %1 1:\trash\%foldername% /s/e
-
- ! remove the temporary variables and delete the original folder
- set foldername=
- deldir "%1"
- ! Note that control will never come back from DELDIR (it was not a CALL).
- ! That is, we will not come back from the command deldir "%1"
- !goto DONE_LBL
-
- :ERR_LBL
- show %doserr%
-
- :DONE_LBL
-